﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace CLIGenProto
{
    public partial class Prompt : Form
    {
        public string Input
        {
            get;
            private set;
        }
        public bool Returned
        {
            get;
            private set;
        }

        public Prompt()
        {
            InitializeComponent();
            Returned = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Input = textBox1.Text;
            this.Hide();
            Returned = true;
        }

        public static string Ask()
        {
            Prompt p = new Prompt();
            p.ShowDialog();
            while (!p.Returned)
                Thread.Sleep(10);
            string ret = p.Input;
            p.Dispose();
            return ret;
        }

        private void Prompt_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                button1_Click(sender, e);
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                button1_Click(sender, e);
        }
    }
}
